#!/usr/bin/python

import cv2
import cv2.cv as cv
from Processor import Processor

filename = "mov1.mp4"

windowName = "A"
cv2.namedWindow(windowName)

capture = cv2.VideoCapture(filename)

nFrames = int(capture.get(cv.CV_CAP_PROP_FRAME_COUNT))
fps = capture.get(cv.CV_CAP_PROP_FPS)
duration = nFrames/fps

fps = 30.0
nFrames = int(duration*fps)
waitPerFrameInMillisec = int( 1/fps * 1000/1 )

print 'Num. Frames = ', nFrames
print 'Frame Rate = ', fps, ' frames per sec (', waitPerFrameInMillisec,')'

proc = Processor()

r, img = capture.read()
hold = False

while( r ):
    proc.process(img)
    
    cv2.imshow(windowName, proc.img)
    key = cv2.waitKey(waitPerFrameInMillisec)   
    if key != -1:
        hold = ~hold
    
    if hold == False:
        r, img = capture.read()
        if key == 101: #e
            r = False

cv2.destroyAllWindows()
